home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue62 / Clinic / TrimWorkingSet.pas < prev   
Encoding:
Pascal/Delphi Source File  |  2000-06-27  |  888 b   |  38 lines

  1. unit TrimWorkingSet;
  2.  
  3. interface
  4.  
  5. implementation
  6.  
  7. uses
  8.   SysUtils, Windows, ExtCtrls;
  9.  
  10. type
  11.   TTrimmer = class(TTimer)
  12.   public
  13.     procedure TimerTick(Sender: TObject);
  14.   end;
  15.  
  16. procedure TTrimmer.TimerTick(Sender: TObject);
  17. var
  18.   CurrentPID, FocusedPID: THandle;
  19. begin
  20.   CurrentPID := GetCurrentProcessId;
  21.   GetWindowThreadProcessId(GetForegroundWindow, @FocusedPID);
  22.   if (Win32Platform = VER_PLATFORM_WIN32_NT) and //running on NT
  23.      (CurrentPID <> FocusedPID) then             //app not foreground process
  24.     SetProcessWorkingSetSize(CurrentPID, Cardinal(-1), Cardinal(-1) );
  25. end;                                                                    
  26.  
  27. var
  28.   Timer: TTrimmer;
  29.  
  30. initialization
  31.   Timer := TTrimmer.Create(nil);
  32.   Timer.Interval := 30000;
  33.   Timer.OnTimer := Timer.TimerTick;
  34. finalization
  35.   if Assigned(Timer) then
  36.     Timer.Free;
  37. end.
  38.